import marimo

__generated_with = "0.8.0"
app = marimo.App()


@app.cell
def __():
    return


@app.cell
def __():
    import pandas as pd
    import matplotlib.pyplot as plt
    import numpy as np
    import os
    return np, os, pd, plt


@app.cell
def __(pd):
    # import pandas as pd
    # import matplotlib.pyplot as plt
    # import numpy as np

    # 前面加_的变量，可以在每个cell中赋值不同？



    _f = pd.read_csv('bom_a.csv')
    _f = _f.loc[_f['cmate'].notna()]
    _f.replace('^\\s+', '', regex=True, inplace=True)
    _f.sort_values(by='Descriptive Part Name', inplace=True, ascending=True)
    _f.drop_duplicates('Descriptive Part Name', keep='first', inplace=True)
    _f.to_csv('bom_b.csv', encoding='utf_8_sig')
    return


@app.cell
def __(os, pd):
    # import pandas as pd
    # import matplotlib.pyplot as plt
    # import numpy as np


    _path = 'D:/study_pro/python_code/pandas'
    os.chdir(_path)
    _csv_f = 'new 2.txt'
    _csv_o = 'new 2o.csv'
    _f = pd.read_csv(_csv_f)
    _f = _f.loc[_f['cmate'].notna()]
    _f.replace('^\\s+', '', regex=True, inplace=True)
    _f.sort_values(by='Descriptive Part Name', inplace=True, ascending=True)
    _f = _f.loc[_f['cmate'].apply(lambda a: a != 'elec')]
    _f.loc[:, 'Descriptive Part Name'].replace('\\s.*?$', '', regex=True, inplace=True)
    _f.to_csv(_csv_o, encoding='utf_8_sig')
    return


@app.cell
def __(os, pd):
    # import pandas as pd
    # import matplotlib.pyplot as plt
    # import numpy as np


    _path = 'D:/study_pro/python_code/pandas'
    os.chdir(_path)
    _csv_f = 'new 3.txt'
    _csv_o = 'new 3o.csv'
    _f = pd.read_csv(_csv_f)
    _f.sort_values(by='a', inplace=True, ascending=True)
    _f.sort_values(by=['a', 'b'], inplace=True, ascending=True)
    _f.to_csv(_csv_o, encoding='utf_8_sig')
    return


@app.cell
def __():
    return


if __name__ == "__main__":
    app.run()
